package cn.bby.tools.actions.str.convert;

import cn.bby.tools.actions.str.BaseStringProcessAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;

import java.util.Set;

/**
 * @author ben
 * @since 2025/9/24 20:27
 */
public class RemoveBracket extends BaseStringProcessAction {
    private final static Set<Character> bracketsStart = Set.of('(', '[', '{');
    private final static Set<Character> bracketsEnd = Set.of(')', ']', '}');
    @Override
    public String process(@NotNull AnActionEvent e, String selectedText) {
        if (bracketsStart.contains(selectedText.charAt(0))) {
            selectedText = selectedText.substring(1);
        }
        if (bracketsEnd.contains(selectedText.charAt(selectedText.length() - 1))) {
            selectedText = selectedText.substring(0, selectedText.length() - 1);
        }
        return selectedText;
    }
}